package com.wxlsoft.config.model;

import java.util.LinkedList;
import java.util.List;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class EsbServiceidentify {

	/**
	 * 服务识别ID
	 */
	private String invokeId;
	
	/**
	 * 所属微服务应用名
	 */
	private String protocolName;	
	
	/**
	 * 识别规则 SvcCd+SvcScn
	 */
	private String identifyExpression;
	
	/**
	 * 识别类型 dynamic
	 */ 
	private String identifyType;	
	
	/**
	 * json
	 */
	private String identifyModel;
	
	
	public static List<EsbServiceidentify> parse(JsonNode data) {
		List<EsbServiceidentify> result = new LinkedList<>();
		ArrayNode records = (ArrayNode) data.get("records");
		
		for (JsonNode record : records) {
			String invokeId = record.get("invokeId").asText();
			String protocolName = record.get("protocolName").asText();
			String identifyExpression = record.get("identifyExpression").asText();
			String identifyType = record.get("identifyType").asText();
			String identifyModel = record.get("identifyModel").asText();
			result.add(new EsbServiceidentify(invokeId, protocolName, identifyExpression, identifyType, identifyModel));
		}
		return result;
	}
	
}
